Skip to content

Remove unreachable NotImplementedException array-with-choice#129491

Open
StephenMolloy wants to merge 1 commit into
dotnet:mainfrom
StephenMolloy:1400-remove-choice-array-guard-in-reflection-XmlSerializer
Open

Remove unreachable NotImplementedException array-with-choice#129491
StephenMolloy wants to merge 1 commit into
dotnet:mainfrom
StephenMolloy:1400-remove-choice-array-guard-in-reflection-XmlSerializer

Conversation

@StephenMolloy

Copy link
Copy Markdown
Member

WriteArray in ReflectionXmlSerializationReader threw NotImplementedException when memberMapping.ChoiceIdentifier was non-null. That memberMapping is a freshly constructed local whose ChoiceIdentifier is always null, so the throw was unreachable dead code. The choice value for an array-typed choice element is recorded by the calling WriteElement against the owning member after WriteArray returns, so the reflection-based serializer already round-trips these types correctly.

Add a regression test covering an [XmlChoiceIdentifier] member where one of the choice element types is itself an array (its element mapping is an ArrayMapping). The test runs in both the codegen and ReflectionOnly XmlSerializer test projects.

Fixes #1400
(Well, not really fixing, because the exception was impossible to hit. But also added some test coverage assurance just in case.)

…eflection-based XmlSerializer (dotnet#1400)

WriteArray in ReflectionXmlSerializationReader threw NotImplementedException when memberMapping.ChoiceIdentifier was non-null. That memberMapping is a freshly constructed local whose ChoiceIdentifier is always null, so the throw was unreachable dead code. The choice value for an array-typed choice element is recorded by the calling WriteElement against the owning member after WriteArray returns, so the reflection-based serializer already round-trips these types correctly.

Add a regression test covering an [XmlChoiceIdentifier] member where one of the choice element types is itself an array (its element mapping is an ArrayMapping). The test runs in both the codegen and ReflectionOnly XmlSerializer test projects.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@StephenMolloy StephenMolloy added this to the 11.0.0 milestone Jun 16, 2026
@StephenMolloy StephenMolloy requested a review from mangod9 June 16, 2026 23:45
@StephenMolloy StephenMolloy self-assigned this Jun 16, 2026
Copilot AI review requested due to automatic review settings June 16, 2026 23:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes an unreachable NotImplementedException in the reflection-based XmlSerializer reader’s array-handling path and adds a regression test to ensure [XmlChoiceIdentifier] works when one of the choice element types is itself an array (ArrayMapping).

Changes:

  • Removed dead/unreachable memberMapping.ChoiceIdentifier != null throw in ReflectionXmlSerializationReader.WriteArray.
  • Added a new round-trip test covering an [XmlChoiceIdentifier] member where one choice element is an array (int[]), validating both value and populated choice-identifier array.
  • Added a small helper type + enum used by the new test.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs Removes unreachable NotImplementedException and documents why choice tracking is handled by the caller (WriteElement).
src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs Adds regression test and supporting types for array-typed choice elements ([XmlChoiceIdentifier] + int[]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ReflectionBasedXmlSerializer] To Support ArrayMapping Types Having ChoiceIdentifier

3 participants